//
//  YJCategoryListCell.m
//  SnackCourier
//
//  Created by qianfeng01 on 15/7/23.
//  Copyright (c) 2015年 qianfeng01. All rights reserved.
//

#import "YJCategoryListCell.h"

@implementation YJCategoryListCell

- (void)awakeFromNib {
    CGFloat w =(self.frame.size.width-5)/4.0;
    CGFloat h =(self.frame.size.height-4)/2.0;
    
    for (int i=0; i<8; i++) {
        self.sView =[[[NSBundle mainBundle] loadNibNamed:@"CategoryView" owner:self options:nil] lastObject];
        self.sView.frame =CGRectMake(1+(i%4)*(1+w), 1+(i/4)*(1+h), w, h);
        self.sView.tag =101 +i;
        [self.contentView addSubview:self.sView];
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
-(void)showDataWithArray:(NSMutableArray *)array myblock:(CategoryBlock)myblock{
    self.array =array;
    self.myblock =myblock;
    for (int i =0; i<array.count; i++) {
        CategoryView *view =(CategoryView *)[self.contentView viewWithTag:101+i];
        [view showWithDataModel:array[i]];
        [view addTarget:self action:@selector(Click:)];
    }
}
-(void)Click:(CategoryView *)view{
    if (self.myblock) {
        YJCategoryModel *mode =self.array[view.tag-101];
        self.myblock(mode);
    }
}

@end
